package com.study.servlet.servletcontext.resource;

import java.io.IOException;
import java.util.Enumeration;
import java.util.ResourceBundle;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* @Name: ReadResourceFileDemo02
* @Description: 使用ResourceBundle读取项目资源属性文件
* 特点：
* 	使用ResourceBundle类，只能加载类路径（即src目录下）目录下的文件，且只能读取属性配置文件
* 	资源文件路径使用基名表示：包名.资源文件名称（不带扩展名）或包名/资源名称（不带扩展名）
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-3-1 上午9:48:50 
* @Version: V1.0
 */
public class ReadResourceFileDemo02 extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ResourceBundle bundle = ResourceBundle.getBundle("com/study/servlet/servletcontext/db") ;
		Enumeration<String> propNames = bundle.getKeys() ;
		while(propNames.hasMoreElements()) {
			String propName = propNames.nextElement() ;
			String propValue = bundle.getString(propName) ;
			System.out.println(propName + ":" + propValue);
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}

}
